/*
 *  Copyright (c) 2013.09.06 BeyondJ2EE.
 *  * All right reserved.
 *  * http://beyondj2ee.github.com
 *  * This software is the confidential and proprietary information of BeyondJ2EE
 *  * , Inc. You shall not disclose such Confidential Information and
 *  * shall use it only in accordance with the terms of the license agreement
 *  * you entered into with BeyondJ2EE.
 *  *
 *  * Revision History
 *  * Author              Date                  Description
 *  * ===============    ================       ======================================
 *  *  beyondj2ee
 *
 */

package org.apache.flume.plugins.partition;

import kafka.producer.Partitioner;
import kafka.utils.VerifiableProperties;

import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @description 轮询的方式选择可用partition
 * @date 2016-12-14 下午5:19
 */
public class PollingPartition implements Partitioner {

    private final AtomicInteger counter = new AtomicInteger(Math.abs((new Random()).nextInt()));

    /**
     * 一定
     *
     * @param props
     */
    public PollingPartition(VerifiableProperties props) {

    }

    @Override
    public int partition(Object key, int partitionSize) {
        int nextValue = this.counter.getAndIncrement();
        return nextValue % partitionSize;
    }
}
